<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <select id="province"></select>
    <select id="city"></select>
    <select id="area"></select>
    <script src="./jquery.js"></script>
    <script src="./template-web.js"></script>
    <script type="text/html" id="provinceTpl">
        {{each data}}
            <option>{{$value}}</option>
        {{/each}}
    </script>
    <script type="text/html" id="cityTpl">
        {{each data}}
            <option>{{$value}}</option>
        {{/each}}
    </script>
    <script type="text/html" id="areaTpl">
        {{each data}}
            <option>{{$value}}</option>
        {{/each}}
    </script>
    <script> 
        //渲染省
        $.ajax({
            type:'get',
            url:'/province',
            success:function(res){
                var html = template('provinceTpl',{data:res})
                $('#province').html(html)
                $('#area').html('')
            }
        })

        //省份切换的时候显示城市
        $('#province').on('change',function(){
            var val = $(this).val()
            $.ajax({
                type:'get',
                url:'/city/'+val,
                success:function(res){
                    var html = template('cityTpl',{data:res})
                    $('#city').html(html)
                }
            })
        })

        //城市切换的时候选择区县
        $('#city').on('change',function(){
            var val = $(this).val()
            $.ajax({
                type:'get',
                url:'/area/'+val,
                success:function(res){
                    var html = template('areaTpl',{data:res})
                    $('#area').html(html)
                }
            })
        })
    </script>
</body>
</html>